import {
    totalConfig,
    propName
} from 'server/config/templateConfig';
import utils from 'server/core/utils';
import equipmentHandle from 'server/handle/equipmentHandle';

let cardsConfig = totalConfig.card;

//调查有1可能遇到怪-发现物品,2获得东西或者武器,3触发任务事件,4获得解密信息

class ExamineHandle {
    static getInstance() {
        if (!ExamineHandle.instance) {
            ExamineHandle.instance = new ExamineHandle();
        }
        return ExamineHandle.instance;
    }

    do(cardId) {
        let cardConfigInfo = cardsConfig[cardId];
        let event = cardConfigInfo.event;
        let eventType = event.eventType;
        if (eventType === 1) {
            return {
                fightMsg: {
                    result: 1, //1胜利,0失败
                },
                exp: 1, //经验
                gold: 1, //金钱
                items: [
                    [200003, 1]
                ]
            }
        } else if (eventType === 2) {
            let random = Math.random() * 100;
            let itemId = null,
                itemNum;
            for (let value of event.items) {
                if (random < value[2]) {
                    itemId = value[0];
                    itemNum = value[1];
                    break;
                }
            }
            if (parseInt(itemId / 10000) === 51) {
                let equipment = equipmentHandle.createByEquipmentId(itemId);
                return {
                    eventType: eventType,
                    items: [
                        [itemId, itemNum, equipment]
                    ]
                };
            } else {
                return {
                    eventType: eventType,
                    items: [
                        [itemId, itemNum]
                    ]
                };
            }

        }
    }

}

export default ExamineHandle.getInstance();